{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import snap\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 1min 33s, sys: 1.1 s, total: 1min 34s\n",
      "Wall time: 1min 35s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#加载数据：http://snap.stanford.edu/data/com-Friendster.html\n",
    "Ugraph = snap.LoadConnList(snap.PUNGraph, \"com-friendster.all.cmty.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 1.07 s, sys: 3 ms, total: 1.07 s\n",
      "Wall time: 1.1 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "snap.PrintInfo(Ugraph,\"Python type PUNGraph\",\"info-pungraph.txt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7944949\n",
      "CPU times: user 999 µs, sys: 999 µs, total: 2 ms\n",
      "Wall time: 1.52 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#图中节点个数\n",
    "print(Ugraph.GetNodes())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20783768\n",
      "CPU times: user 999 µs, sys: 2 ms, total: 3 ms\n",
      "Wall time: 1.88 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#图中边数\n",
    "print(Ugraph.GetEdges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "410\n",
      "CPU times: user 1.32 s, sys: 4 ms, total: 1.33 s\n",
      "Wall time: 1.43 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#度为100的节点个数\n",
    "print(snap.CntDegNodes(Ugraph, 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "410\n",
      "CPU times: user 1.08 s, sys: 1e+03 µs, total: 1.08 s\n",
      "Wall time: 1.08 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#出度为100的节点个数\n",
    "print(snap.CntOutDegNodes(Ugraph, 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "410\n",
      "CPU times: user 971 ms, sys: 1 ms, total: 972 ms\n",
      "Wall time: 969 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#入度为100的节点个数\n",
    "print(snap.CntInDegNodes(Ugraph, 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3922991\n",
      "CPU times: user 1.34 s, sys: 2 ms, total: 1.34 s\n",
      "Wall time: 1.36 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#有着最大出度的节点的id\n",
    "print(snap.GetMxOutDegNId(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3922991\n",
      "CPU times: user 947 ms, sys: 6 ms, total: 953 ms\n",
      "Wall time: 952 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#有着最大入度的节点的id\n",
    "print(snap.GetMxInDegNId(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42236\n",
      "CPU times: user 43.1 s, sys: 253 ms, total: 43.3 s\n",
      "Wall time: 43.4 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#Components是弱连通网络集合\n",
    "Components = snap.TCnComV()\n",
    "snap.GetWccs(Ugraph, Components)\n",
    "print(Components.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "37\n",
      "CPU times: user 35 s, sys: 273 ms, total: 35.3 s\n",
      "Wall time: 35.3 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#ComponentDist相当于对Components按<弱连通网络中节点数大小>进行了分组\n",
    "ComponentDist = snap.TIntPrV()\n",
    "snap.GetWccSzCnt(Ugraph, ComponentDist)\n",
    "print(ComponentDist.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7835772\n",
      "CPU times: user 24.4 s, sys: 1e+03 µs, total: 24.4 s\n",
      "Wall time: 24.4 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#和节点4025014在同一个弱连通网路的节点集合\n",
    "CnCom = snap.TIntV()\n",
    "snap.GetNodeWcc(Ugraph, 4025014, CnCom)\n",
    "# print \"Nodes in the same connected component as node 0:\"\n",
    "# for node in CnCom:\n",
    "#     print node\n",
    "# print('--')\n",
    "print(CnCom.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7835772\n",
      "20716047\n",
      "CPU times: user 2min 9s, sys: 1.15 s, total: 2min 10s\n",
      "Wall time: 2min 10s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#最大的弱连通图节点数和边数\n",
    "MxWcc = snap.GetMxWcc(Ugraph)\n",
    "print(MxWcc.GetNodes())\n",
    "print(MxWcc.GetEdges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.986258313301\n",
      "CPU times: user 32.7 s, sys: 175 ms, total: 32.9 s\n",
      "Wall time: 32.9 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#最大的弱连通图的节点相对大小\n",
    "print(snap.GetMxWccSz(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42236\n",
      "CPU times: user 1min 1s, sys: 913 ms, total: 1min 2s\n",
      "Wall time: 1min 2s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#Components是强连通网络集合\n",
    "Components = snap.TCnComV()\n",
    "snap.GetSccs(Ugraph, Components)\n",
    "print(Components.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "37\n",
      "CPU times: user 55.4 s, sys: 279 ms, total: 55.6 s\n",
      "Wall time: 55.7 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#ComponentDist相当于对Components按<强连通网络中节点数大小>进行了分组\n",
    "ComponentDist = snap.TIntPrV()\n",
    "snap.GetSccSzCnt(Ugraph, ComponentDist)\n",
    "print(ComponentDist.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7835772\n",
      "20716047\n",
      "CPU times: user 4min 17s, sys: 1.55 s, total: 4min 19s\n",
      "Wall time: 4min 19s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#最大的强连通图的节点数和边数\n",
    "MxWcc = snap.GetMxScc(Ugraph)\n",
    "print(MxWcc.GetNodes())\n",
    "print(MxWcc.GetEdges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.986258313301\n",
      "CPU times: user 1min 17s, sys: 18 ms, total: 1min 17s\n",
      "Wall time: 1min 17s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#最大的强连通图的节点相对大小\n",
    "print(snap.GetMxSccSz(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4344495\n",
      "17212428\n",
      "CPU times: user 5min 48s, sys: 1.37 s, total: 5min 49s\n",
      "Wall time: 5min 49s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#有向图的最大双连通图网络的节点数和边数\n",
    "BiCon = snap.GetMxBiCon(Ugraph)\n",
    "print(BiCon.GetNodes())\n",
    "print(BiCon.GetEdges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "615584\n",
      "CPU times: user 1min 6s, sys: 41 ms, total: 1min 6s\n",
      "Wall time: 1min 6s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#articulation points:返回无向图的连接点集合\n",
    "ArtNIdV = snap.TIntV()\n",
    "snap.GetArtPoints(Ugraph, ArtNIdV)\n",
    "print(ArtNIdV.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3534315\n",
      "CPU times: user 4min 33s, sys: 465 ms, total: 4min 33s\n",
      "Wall time: 4min 33s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#edge bridges:类似articulation points，只不过是针对边说的\n",
    "EdgeV = snap.TIntPrV()\n",
    "snap.GetEdgeBridges(Ugraph, EdgeV)\n",
    "print(EdgeV.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6169038\n",
      "CPU times: user 7min 47s, sys: 853 ms, total: 7min 48s\n",
      "Wall time: 7min 48s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#互连三元祖闭合环个数\n",
    "print(snap.GetTriads(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closed triads 6169038\n",
      "open triads 10439748758\n",
      "CPU times: user 8min 37s, sys: 641 ms, total: 8min 38s\n",
      "Wall time: 8min 38s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#互连三元祖闭合环个数和非闭合环个数\n",
    "result = snap.GetTriadsAll(Ugraph)\n",
    "print \"closed triads\", result[0]\n",
    "print \"open triads\", result[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7243985\n",
      "CPU times: user 18min 50s, sys: 7 ms, total: 18min 50s\n",
      "Wall time: 18min 51s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#参与互连三元祖闭合环的边数\n",
    "print(snap.GetTriadEdges(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Aggregation coefficient set grouped by degree 2100\n",
      "average clustering coefficient 0.0867827397672\n",
      "closed triads 6169038\n",
      "open triads 10439748758\n",
      "CPU times: user 6min 41s, sys: 874 ms, total: 6min 42s\n",
      "Wall time: 6min 42s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#按度分组聚集系数集合，总平均聚集系数、闭合环个数、非闭合环个数\n",
    "DegToCCfV = snap.TFltPrV()\n",
    "result = snap.GetClustCfAll(Ugraph, DegToCCfV)\n",
    "print \"Aggregation coefficient set grouped by degree\",DegToCCfV.Len()\n",
    "print \"average clustering coefficient\", result[0]\n",
    "print \"closed triads\", result[1]\n",
    "print \"open triads\", result[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "CPU times: user 7min 35s, sys: 153 ms, total: 7min 35s\n",
      "Wall time: 7min 35s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#利用广度遍历来求得图的近似直径值\n",
    "print(snap.GetBfsFullDiam(Ugraph, 10, False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.83603477105\n",
      "CPU times: user 5min 53s, sys: 68 ms, total: 5min 53s\n",
      "Wall time: 5min 53s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#91-th percentile of the distribution的近似直径值\n",
    "print(snap.GetBfsEffDiam(Ugraph, 10, False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4132\n",
      "CPU times: user 497 ms, sys: 1 ms, total: 498 ms\n",
      "Wall time: 496 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#距离节点4025014两跳可以到达的节点集合\n",
    "NodeVec = snap.TIntV()\n",
    "snap.GetNodesAtHop(Ugraph, 4025014, 2, NodeVec, False)\n",
    "print(NodeVec.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "CPU times: user 3.48 s, sys: 0 ns, total: 3.48 s\n",
      "Wall time: 3.48 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#节点4025014和114322660的最短路径长度\n",
    "print(snap.GetShortPath(Ugraph,4025014,114322660,False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.49528180031\n",
      "CPU times: user 6min 51s, sys: 425 ms, total: 6min 52s\n",
      "Wall time: 6min 52s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#最短路径分布的90-th percentile\n",
    "print(snap.GetAnfEffDiam(Ugraph))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13658750\n",
      "CPU times: user 1min 29s, sys: 559 ms, total: 1min 30s\n",
      "Wall time: 1min 30s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#以节点4025014为根节点得到到其他节点的树结构\n",
    "BfsTree = snap.GetBfsTree(Ugraph, 4025014, True, False)\n",
    "# for EI in BfsTree.Edges():\n",
    "#     print \"Edge from %d to %d in generated tree.\" % (EI.GetSrcNId(), EI.GetDstNId())\n",
    "print(BfsTree.GetEdges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%time\n",
    "#基于NodeFrac节点的样本计算节点和边的中心性近似值集合\n",
    "Nodes = snap.TIntFltH()\n",
    "Edges = snap.TIntPrFltH()\n",
    "snap.GetBetweennessCentr(Ugraph, Nodes, Edges, 1.0)\n",
    "# for node in Nodes:\n",
    "#     print \"node: %d centrality: %f\" % (node, Nodes[node])\n",
    "# for edge in Edges:\n",
    "#     print \"edge: (%d, %d) centrality: %f\" % (edge.GetVal1(), edge.GetVal2(), Edges[edge])\n",
    "print(Nodes.Len())\n",
    "print(Edges.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.68962640778\n",
      "CPU times: user 10 s, sys: 85 ms, total: 10.1 s\n",
      "Wall time: 10.1 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#节点4025014的farness centrality\n",
    "print(snap.GetFarnessCentr(Ugraph, 4025014))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.213236602033\n",
      "CPU times: user 10.1 s, sys: 154 ms, total: 10.2 s\n",
      "Wall time: 10.3 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#节点4025014的closeness centrality：是farness centrality的倒数\n",
    "print(snap.GetClosenessCentr(Ugraph, 4025014))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7944949\n",
      "CPU times: user 1min 52s, sys: 545 ms, total: 1min 53s\n",
      "Wall time: 1min 53s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算每个节点的PageRank分数集合\n",
    "PRankH = snap.TIntFltH()\n",
    "snap.GetPageRank(Ugraph, PRankH)\n",
    "# for item in PRankH:\n",
    "#     print item, PRankH[item]\n",
    "print(PRankH.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7944949\n",
      "7944949\n",
      "CPU times: user 19min 30s, sys: 704 ms, total: 19min 31s\n",
      "Wall time: 19min 31s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算每个节点的Hubs和Authorities分数集合\n",
    "NIdHubH = snap.TIntFltH()\n",
    "NIdAuthH = snap.TIntFltH()\n",
    "snap.GetHits(Ugraph, NIdHubH, NIdAuthH)\n",
    "# for item in NIdHubH:\n",
    "#     print item, NIdHubH[item]\n",
    "# for item in NIdAuthH:\n",
    "#     print item, NIdAuthH[item]\n",
    "print(NIdHubH.Len())\n",
    "print(NIdAuthH.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n",
      "CPU times: user 24.3 s, sys: 84 ms, total: 24.4 s\n",
      "Wall time: 24.4 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#id为4025014这个节点的node eccentricity:节点偏心率，即从节点0到图中任何其他节点的最大最短路径距离\n",
    "print(snap.GetNodeEcc(Ugraph,4025014, False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%time\n",
    "#社区的集合：关于社区的概念https://blog.csdn.net/cleverlzc/article/details/39494957\n",
    "#使用的是Clauset-Newman-Moore community detection method算法\n",
    "CmtyV = snap.TCnComV()\n",
    "modularity = snap.CommunityCNM(Ugraph, CmtyV)\n",
    "# for Cmty in CmtyV:\n",
    "#     print \"Community: \"\n",
    "#     for NI in Cmty:\n",
    "#         print NI\n",
    "print \"The modularity of the network is %f\" % modularity\n",
    "print(CmtyV.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#社区的集合\n",
    "#使用的是 Girvan-Newman community detection algorithm算法\n",
    "CmtyV = snap.TCnComV()\n",
    "modularity = snap.CommunityGirvanNewman(Ugraph, CmtyV)\n",
    "# for Cmty in CmtyV:\n",
    "#     print \"Community: \"\n",
    "#     for NI in Cmty:\n",
    "#         print NI\n",
    "print \"The modularity of the network is %f\" % modularity\n",
    "print(CmtyV.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "387.264224046\n",
      "256.192033973\n",
      "-381.681435039\n",
      "CPU times: user 3min 17s, sys: 1.18 s, total: 3min 18s\n",
      "Wall time: 3min 18s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算无向图邻接矩阵前EigVals个的特征值集合\n",
    "EigVals = 3\n",
    "PEigV = snap.TFltV()\n",
    "snap.GetEigVals(Ugraph, EigVals, PEigV)\n",
    "for item in PEigV:\n",
    "    print item"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 7944949\n",
      "CPU times: user 4min 29s, sys: 1.74 s, total: 4min 31s\n",
      "Wall time: 4min 31s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算计算无向图邻接矩阵的第一列特征向量集合\n",
    "EigVec =  snap.TFltV()\n",
    "snap.GetEigVec(Ugraph, EigVec)\n",
    "# for Val in EigVec:\n",
    "#     print Val\n",
    "print(EigVec.Len())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-363.123467, 0.191928\n",
      "-28.712595, 0.002063\n",
      "50.858960, 0.004579\n",
      "370.633989, 0.174107\n",
      "CPU times: user 4min 4s, sys: 3.27 s, total: 4min 8s\n",
      "Wall time: 4min 8s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算Inverse participation ratio，最大搜索时间50秒，最大的返回特征数量数为5\n",
    "EigValIprV = snap.TFltPrV()\n",
    "snap.GetInvParticipRat(Ugraph, 5, 50, EigValIprV)\n",
    "for item in EigValIprV:\n",
    "    print '%f, %f' % (item.GetVal1(), item.GetVal2())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No Core exists for K=100\n",
      "CPU times: user 17.7 s, sys: 85 ms, total: 17.8 s\n",
      "Wall time: 17.8 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算K-score为K的网络集合\n",
    "K = 100\n",
    "KCore = snap.GetKCore(Ugraph, K)\n",
    "if KCore.Empty():\n",
    "    print 'No Core exists for K=%d' % K\n",
    "else:\n",
    "    print 'Core exists for K=%d' % K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 32.9 s, sys: 170 ms, total: 33.1 s\n",
      "Wall time: 33.1 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算得到每个K-score中的节点数\n",
    "CoreIDSzV = snap.TIntPrV()\n",
    "kValue = snap.GetKCoreNodes(Ugraph, CoreIDSzV)\n",
    "# for item in CoreIDSzV:\n",
    "#     print \"order: %d nodes: %d\" % (item.GetVal1(), item.GetVal2())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 47 s, sys: 163 ms, total: 47.1 s\n",
      "Wall time: 47.1 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "#计算得到每个K-score中的边数\n",
    "CoreIDSzV = snap.TIntPrV()\n",
    "kValue = snap.GetKCoreEdges(Ugraph, CoreIDSzV)\n",
    "# for item in CoreIDSzV:\n",
    "#     print \"order: %d edges: %d\" % (item.GetVal1(), item.GetVal2())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
